﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using WAD.Client2.WXPay;
using WAD.WEB.AppCode;

namespace WAD.Client2.Client2.Ajax
{
    /// <summary>
    /// WxJsApi 的摘要说明
    /// </summary>
    public class WxJsApi : AjaxBase
    {
        public override void AjaxMethodDispatch(String identity)
        {
            switch (identity)
            {
                case "get": this.Get(); break;
            }
        }
        [QD.Web.Ajax.AjaxMethod]
        public void Get()
        {
            try
            {
                var fee = Parse.Int("fee", 0);
                var jsApiPay = new JsApiPayForHttpContext(this.Context);
                if(string.IsNullOrEmpty(jsApiPay.openid))
                //调用【网页授权获取用户信息】接口获取用户的openid和access_token
                jsApiPay.GetOpenidAndAccessToken();
                Log.Debug(this.GetType().ToString(), "openID : " + jsApiPay.openid);
                Log.Debug(this.GetType().ToString(), "access_token : " + jsApiPay.access_token);
                jsApiPay.total_fee = fee;
                var unifiedOrderResult = jsApiPay.GetUnifiedOrderResult();
                var wxJsApiParam = jsApiPay.GetJsApiParameters();//获取H5调起JS API参数  
                Log.Debug(this.GetType().ToString(), "wxJsApiParam : " + wxJsApiParam);
                Success(wxJsApiParam);

            }
            catch(Exception e)
            {
               Fail(e.Message);
            }
            

        }

    }
}